/**
 * @file       IPEditField_test.cpp
 * @brief      TODO
 * @author     Huabo Zheng
 * @date       Jan 12, 2012
 * @Copyright  2012, www.netgear.com Inc. All rights reserved.
 */

#include "IPEditField.h"
#include "gtest/gtest.h"
#include "errorcode.h"
namespace NS_LCD_AFW
{
class CIPEditField_test: public ::testing::Test
{
public:
	virtual void SetUp()
	{
	}
	virtual void TearDown()
	{
	}
};
TEST_F(CIPEditField_test,test_defualtConstruction)
{
	CIPEditField *pField = new CIPEditField();
	EXPECT_TRUE(pField->isHightlightable());
	EXPECT_TRUE(pField->isFocusable());
	OBJ_DESTORY(pField);
}
TEST_F(CIPEditField_test,test_setIP)
{
	CIPEditField *pField = new CIPEditField();
	EXPECT_EQ(ERR_SUCCESS,pField->create("IPEDITOER",CRect(0,0,15,1)));
	EXPECT_EQ(ERR_SUCCESS,pField->setIP(192,168,0,1));
	EXPECT_EQ("192.168.000.001",pField->getIP());
	EXPECT_EQ(ERR_SUCCESS,pField->setIP("10.0.192.12"));
	EXPECT_EQ("010.000.192.012",pField->getIP());
	OBJ_DESTORY(pField);
}
TEST_F(CIPEditField_test,test_getIP)
{
	CIPEditField *pField = new CIPEditField();
	EXPECT_EQ(ERR_SUCCESS,pField->create("IPEDITOER",CRect(0,0,15,1)));
	EXPECT_EQ(ERR_SUCCESS,pField->setIP(192,168,0,1));
	EXPECT_EQ("192.168.000.001",pField->getIP());
	EXPECT_EQ(ERR_SUCCESS,pField->setIP("10.0.192.12"));
	EXPECT_EQ("010.000.192.012",pField->getIP());
	OBJ_DESTORY(pField);
}

TEST_F(CIPEditField_test,test_isValidIpAddress)
{
	EXPECT_TRUE(CIPEditField::isValidIpAddress("0.0.0.0"));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("192.168.0.0"));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("192.168.0.1"));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("192.168.000.001"));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("192.168.000.002"));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("192.168.010.1"));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("192.168.10.1"));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("192.168.10.10"));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("192.168.10.100"));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("10.0.00.000"));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("210.10.0.010"));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("255.255.255.255"));

	EXPECT_TRUE(CIPEditField::isValidIpAddress("0.0.0"));
	EXPECT_FALSE(CIPEditField::isValidIpAddress(""));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("0"));
	EXPECT_TRUE(CIPEditField::isValidIpAddress("255"));
	EXPECT_FALSE(CIPEditField::isValidIpAddress("256.0.0.0"));
	EXPECT_FALSE(CIPEditField::isValidIpAddress("256.256.256.256"));
	EXPECT_FALSE(CIPEditField::isValidIpAddress("-1.-1.-1.-1"));
	EXPECT_FALSE(CIPEditField::isValidIpAddress("abcd"));
	EXPECT_FALSE(CIPEditField::isValidIpAddress("$&%&^*&(*^$#"));
}
TEST_F(CIPEditField_test,test_uChar2Str)
{
	EXPECT_EQ("192",CIPEditField::uChar2Str(192));
	EXPECT_EQ("000",CIPEditField::uChar2Str(0));
	EXPECT_EQ("010",CIPEditField::uChar2Str(10));
	EXPECT_EQ("100",CIPEditField::uChar2Str(100));
}
TEST_F(CIPEditField_test,test_formatIpAddress)
{
	EXPECT_EQ("000.000.000.000",CIPEditField::formatIpAddress("0.0.0.0"));
	EXPECT_EQ("000.000.000.000",CIPEditField::formatIpAddress("0.0.0"));
	EXPECT_EQ("000.000.000.000",CIPEditField::formatIpAddress("0"));
	EXPECT_EQ("000.000.000.000",CIPEditField::formatIpAddress(""));


	EXPECT_EQ("192.016.008.001",CIPEditField::formatIpAddress("192.16.010.1"));

	EXPECT_EQ("192.016.008.018",CIPEditField::formatIpAddress("192.16.010.0x12"));

	EXPECT_EQ("192.016.100.001",CIPEditField::formatIpAddress("192.16.100.1"));

	EXPECT_EQ("192.016.000.001",CIPEditField::formatIpAddress("192.16.0.1"));

	EXPECT_EQ("000.000.000.000",CIPEditField::formatIpAddress("256.0.0.255"));
	EXPECT_EQ("000.000.000.000",CIPEditField::formatIpAddress("-1,-1.-1@-1"));
}
} /* namespace NS_LCD_AFW */
